Scripting Tutorial: Aliases



Alright! Now we'll create our first Alias which will make your mIRC say "Hello World!" when you type /hw in a channel window. Type the following code in any window.

/alias /hw /msg $chan Hello World!

If you did it correctly you should see "* Added '/hw' alias" in the window where you typed it. Now type /hw in a channel and see what happens. Congratulations!

Now let me explain what we did exactly. We created an Alias from the command line (where you type in your text, it can be any window) using the command /alias. In the introduction chapter we talked about creating Aliases in the Aliases mode of the Editor. Are you a little confused? Don't be. Open the Editor and check the Aliases. There it is! /hw /msg $chan Hello World! I usually use the command line to create Aliases which I commonly use. It's my personal preference again. If you feel like opening the Editor and making the entries manually you can very well do that too.

/alias is the command you use to create an Alias. The format for creating an alias is:
/alias <alias-name> <command>

Now let's get on to something more interesting. Create an Alias called "how" for "/msg $chan Hiya $1! howya doin?". Type the following to create the alias.

/alias /how /msg $chan Hiya $1! howya doin?

Now type /how Some-nick-in-channel and see what you get. Well, you need to replace Some-nick-in-channel with some in nick which's in the channel or you will end up looking like an idiot.

Now wasn't that cool? Did you notice the $chan and $1 in the codes? They are called Identifiers. They've got predefined values set by mIRC. We will learn more about Identifiers later. The Identifier $chan is the active channel you are on. $1 represents the first string you type after /how. The first string will take the position of $1 in the command: the nickname you typed replaced the position of $1. Create the following Aliases and see what they do, you will be clear about the $1 thing.

/alias /how1 /msg $chan Hiya $1! Howya doin?
/alias /how2 /msg $chan Hiya $2! Howya doin?
/alias /how3 /msg $chan Hiya $3! Howya doin?

Type the following to see the result:

/how1 007 hacker crane c
/how2 lion dog cat
/how3 batman ninja kung-fu


Got some idea? Next we create a new Alias /ss which takes two parameters.

/alias /ss /msg $chan Hey $1! Do u like $2?

Now type /ss Henry monkeys in the channel. It will say "Hey Henry! Do u like monkeys?". Replace Henry and monkeys with some other strings (words) and see the result. Did you notice how monkeys, which is the 2nd word after /ss, replaced the position of $2. Likewise using your imagination you can include $3, $4, $5 etc. If you put a - after $N, it will include all the words after the number N. For eg: $2- means; all the words after the 2nd word after your Alias command.

The Alias names /hw and /ss are my own creations, you may put whatever letters you want to put according to your preferences for your aliases. Note: Alias names don't support spaces.

Try out these Aliases; it will give you some idea about how they work.

/alias /look /say $1! you look like $2- type /look <nick> an ostrich!
/alias /kk /me kicks $1 in the ass * $+ $2 $+ * type /kk <nick> <sound effect>
/alias /nn /notice $1 $2- type /nn <nick> <message>
/alias /op /mode # +o $1 type /op <nick> in the channel where you are an OP

The front slashes (/) before the name of the Alias and the Command are optional. If you are new to scripting you might like to use them so that you don't get confused about what's goin on where. /alias op mode # +o $1 will do the same thing as /alias /op /mode # +o $1

To be able to create interesting and useful Aliases you need to have some knowledge about mIRC commands, Identifiers and Variables. You can use color codes, bold face and reverse in the text from the Aliases. It applies to all other type of script files too.

So far we have created only single command Aliases. Meaning when you call (envoke) an Alias, it executes only one command; like saying "Hello World!". Now we will get a little bit more complex and start writing Aliases that perform more than one task at a go. For that we've got two options. You can either do it from the command line (window text input area) or right in the Editors's Alias mode. To do it from the command line, you add the additional commands separated by a | (bar). In the Editor you enclose the command codes within { } (curly brackets). Let's create an Alias which performs multiple tasks.

Option 1:
/alias /cookie /me is eating a cookie *chomp! chomp!* | say anybody want some? | me is now digesting the cookie

Option 2:
/cookie {
  me is eating a cookie *chomp! chomp!*
  say anybody want some?
  me is now digesting the cookie.
}

Both of the above codes will create the same Alias with the same functions. But you may like to use the second option if you think your codes are gonna be very lengthy. I hope by this time you must've figured how to call an Alias. How do you call that cookie Alias? type /cookie in the command line (text input line in the mIRC window; can be any window).

Aliases are not only used for printing out texts in a window. You can use them to perform any of the mIRC functions. Use your imagination. Here's an example of how using Aliases you can set the topic for a channel (if you have the previlege).

/alias /t /topic # $1-

Now when you type /t Blah! Blah! Blah! in a channel window command line, it will set the topic for the channel to Blah! Blah! Blah!

To delete alias created in the aliases file, type /alias <alias name>. Removing alias definitions in the remote files will need you to open the remote file and delete the definition manually.

In the introduction part I mentioned about the ability to create Aliases right from the Remotes. You can read about it in the Remotes chapter. Read up the mIRC Commands from the Help File, use your imagination and you can come up with many cool ideas on how and where you can use Aliases.


Back | Table of Contents | Popups



Copyright © 2002-2004 SpyderWares.
Feel free to distribute this tutorial in part or whole, just make sure the credits stay intact.

http://spyderwares.com